<template>
  <div class="item">
    <input
      class="checkbox"
      type="checkbox"
      value="true"
      :checked="propItem?.checked"
      @change="onChange"
    />
    <text class="title">{{ propItem?.title }}</text>
    <text class="icon-delete" @click="onDelete">X</text>
  </div>
</template>

<script lang="ts">
import { defineComponent } from '@vue/composition-api'
import { useList } from '../stores/dailySign'
import { MyItemType } from '../common/type'
import { toRefs } from 'vue'

export default defineComponent({
  props: {
    item: MyItemType,
  },
  setup(props, context) {
    const { item: propItem } = toRefs(props)
    const { deleteItem, checkedItem } = useList()

    const id = propItem && propItem.value ? Number(propItem.value.id) : 0
    const onDelete = () => deleteItem(id)
    const onChange = () => checkedItem(id)
    return {
      onDelete,
      onChange,
      propItem: propItem?.value,
    }
  },
})
</script>

<style scoped>
.item {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.checkbox {
  background-color: red;
  color: red;
}

.title {
  flex: 1;
  color: #555;
  margin: 0 20px;
  padding: 5px 10px;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.1);
}

.icon-delete {
  font-size: xx-large;
  font-weight: bold;
  cursor: pointer;
  color: #aaa;
}
</style>
